module Geometry.Geometry where
import Data.VectorSpace
import Number.Quaternion

type Point2D  = (Double, Double)
type Polar2D  = (Radius, Angle)
type Angle    = Double 
type Radius   = Double
type Polar3D  = (Radius, Angle, Angle)
type Point3D  = (Double, Double, Double)
type Vector3D = (Double, Double, Double)

fromPolar2D :: Polar2D -> Point2D
fromPolar2D (r,a) = (r*cos a, r*sin a)

toPolar2D :: Point2D -> Polar2D
toPolar2D (x,y) | y >= 0 = (r,a)
                | otherwise = (r,-a)
  where r = magnitude (x,y)
        a = acos (x/r)


fromPolar3D :: Polar3D -> Point3D
fromPolar3D (r,a,d) = let x = r * cos a * cos d
                          y = r * sin a * cos d
                          z = r * sin d
                      in (x,y,z)
                         
toPolar3D :: Point3D -> Polar3D
toPolar3D (x,y,z) = let (r',a) = toPolar2D (x,y)
                        (r,d)  = toPolar2D (r',z)
                    in (r,a,d)

toRadian :: Angle -> Angle
toRadian a = pi*a/180

rotateAxis :: Angle -> Vector3D -> Vector3D -> Vector3D
rotateAxis a v0 v1 = imag p' 
  where
    p' = similarity (cos (a/2) +:: (sin (a/2) *^ p)) (0 +:: v1)
    p  = normalized v0

                                                  
                                                
                                                 